home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-03-02 | 8.9 KB | 268 lines | [TEXT/MPS ] |
- file fixit.txt Copyright (C) 1996 by John Montbriand. All Rights Reserved.
-
- ABOUT FIXIT...
-
- Copyright (C) 1996 by John Montbriand. All Rights Reserved.
-
- Distribute freely in areas where the laws of copyright apply.
-
- Use at your own risk.
-
- Do not distribute modified copies.
-
- These various fixmath routines and libraries are for free!
-
-
- ABOUT THE AUTHOR...
-
- Comments, questions, or suggestions are always welcome.
-
- John Montbriand tinyjohn@sasknet.sk.ca
- P.O. Box. 1133
- Saskatoon Saskatchewan Canada
- S7K 3N2
-
-
- WHY IS IT FOR FREE?
-
- none of your business,
-
- but if you have some business for me, I'll see what I can do..
-
-
- OUTLINE OF TOPICS
-
- FIXIT, WHAT'S IT DO? WHAT'S IT FOR?
- IMPLEMENTATION NOTES
- MATERIALS
- LEGAL STUFF
- FURTHER REFERENCE
- BE CAREFUL (CAVEATS)
- THE FIXIT TOOL
- FIXIT INPUT FORMAT
- ROUTINES PROVIDED
-
-
- FIXIT, WHAT'S IT DO? WHAT'S IT FOR?
-
- Fixit is an MPW tool that translates easily readable infix
- mathematical expressions into difficult to read and edit fixed
- point math function calling sequences that are suitable for
- use as expressions in C programs.
-
- It also serves as a fixed point expression evaluator.
-
- On most macintoshes, the fixed point math functions are much faster
- than using floating point functions and in some cases they can
- be a very attractive alternative for mathematical processing.
-
-
- IMPLEMENTATION NOTES
-
- Some fixed point functions are not defined in the current collection
- Fixed point math routines, hence they have been included here
- in the file fixit.c. These routines include fixed point functions
- for calculating square root, exponent, square, cosine, sine, and tangent.
- These are described in greater detail below.
-
- The Fixit tool does some constant sub expression (cse) optomization which
- allows you to use it as a fixed point number calculator. The following
- table illustrates how this happens:
-
- input output
-
- cos(3.14 / (22.5 + 7)) 0x0000FE8D
- 88.32 + 77/12 0x005EBC97
- sqrt(7.3 - 3)/my_var FixDiv(0x000212DB, my_var)
- 3.14159 0x0003243F
- (value/16.4) * i + 77 (FixMul(FixDiv(value, 0x00106666), i) + 0x004D0000)
-
- note: the cse optomization does not modify the expression tree in its
- search for constant sub expressions as it could so hence some constant
- sub expressions that could be optomized out are not. For example, the
- expression 4 + x + 5 simplifies to ((0x00040000 + x) + 0x00050000) when
- if the original expression could have been rewritten to group the
- constants together as in 4 + 5 + x to yeild the expression
- (0x00090000 + x). This sort of searching could have been done
- automatically, but in this version of fixit it is not.
-
-
- MATERIALS
-
- The Fixed point number format itself is the copyright property of
- Apple computer and has been known to the public since 1983.
-
- The routines documented herein are the copyright property of
- John Montbriand. I am making these routines available to the
- macintosh programming community because I feel it's about time
- someone did! I hope all who find them, use them well.
-
- Compiled and tested with MPW C, MW C, SC, and MPW PPC.
-
-
- LEGAL STUFF
-
- These libraries are provided for free and you may use them
- in any program you make; however, if you're particular about
- having signed documentation that proves this fact in your posession
- then, as I would like to ensure these libraries are widely used,
- I would be glad provide such documents for you.
-
- I don't think this is entirly necessary, but I can understand
- that some folks feel quite strongly about such issues and prefer
- to do things in writing.
-
- If you would like for me to send you a signed document saying
- that you have license to use these routines in your programs,
- then send me a couple of bucks to cover postage and handling
- and I'll send you back a signed letter saying you have license
- to use these routines in any software you make.
-
- I think two or three dollars is fair as I don't really get a big
- thrill out of printing stuff out and mailing it, and that's usually
- enough to cover postage to anywhere in the world. I s'pose you'd have
- to figure out how much it would cost for me to mail a letter to you
- from here in Canada.
-
-
- FURTHER REFERENCE
-
- The files fixit.h and fixit.c contain some additional fixed math routines
- documented below.
-
- fixit.y and fixit.l contain the yacc and lex source code for the fixit MPW tool.
-
- Documentation regarding the fixed point data type and functions defined
- inside of the toolbox for utilizing it can be found in the following
- sources:
-
- Inside Macintosh Volume 4, by Apple Computer. pub. Addison Wesley.
- (page 63) A discussion of the new fixed point math routines introduced
- along with the MacPlus. These routines include the additional routines
- defined beyond FixMul, FixRatio, and FixRound.
-
- Mathematical and Logical Utilities chapter of Inside Macintosh: Operating
- System Utilities, by Apple Computer. pub. Addison Wesley. (page 3-3)
-
- The C Programming Language 2nd edition by Brian W. Kernighan
- and Dennis M. Ritchie. Prentice Hall.
-
- Deviant Logic by Susan Haack. Cambridge University Press.
-
- Comments for the routines provided herein have been included in the
- file fixit.h.
-
-
- BE CAREFUL (CAVEATS)
-
- I think these routines are safe to use, but you should do your own
- testing. I have provided the source code, and if you find any bugs,
- please let me know right away so I can provide corrections in future
- versions.
-
- I advertise a finder's fee of $10.00 cash for errors in any
- of my products.
-
-
- THE FIXIT TOOL
-
- fixit is an MPW tool that converts an expression read from standard
- input into a sequence of fixed point routine calls that calculate the
- same result. The command line format for the fixit tool is as
- follows:
-
- fixit < input > output
-
- fixit reads text in the format of infix mathematical expressions
- from standard input writing the resuling fixmath routine calls
- making up the expression to standard output.
-
- Here's a useful key redefinition for the tool allowing you to select
- an expression in a window and automatically generate a set of fixed
- point routine calls for it:
-
- SetKey F11 'fixit < "{Active}".§ > "{MPW}"tempxx ; ∂
- catenate "{MPW}"tempxx > "{Active}".§; delete "{MPW}"tempxx'
-
- example:
- echo "2+2" | fixit
- yeilds -> 0x00040000
-
- note: providing a parameter to the fixit tool forces it to
- print out some help text.
-
-
- FIXIT INPUT FORMAT
-
- input format for the fixit tool consists of a single infix expression.
- If the expression contains any identifiers, they are assumed to be
- variable names and are echoed to output in the correct position in the
- expression. The bnf for expressions follows:
-
- expression ::= '(' expression ')'
- expression ::= expression '+' expression
- expression ::= expression '-' expression
- expression ::= expression '*' expression
- expression ::= expression '/' expression
- expression ::= expression '**' expression
- expression ::= 'sin' '(' expression ')'
- expression ::= 'cos' '(' expression ')'
- expression ::= 'tan' '(' expression ')'
- expression ::= 'sqr' '(' expression ')'
- expression ::= 'sqrt' '(' expression ')'
- expression ::= '-' expression
- expression ::= identifier
- expression ::= number
- number ::= integer
- number ::= integer '.' integer
-
- Order of evaluation is the same as the standard mathematical operations
- in the following order of precidence: parentheses, unary minus,
- exponent, multiply/divide, and then add/subtract.
-
- Library support for the functions sin, cos, tan, sqr, sqrt, and the
- exponential operator ** is provided in the file fixit.c. If you use
- the fixit tool, you should link with a compiled version of this file.
-
- The fixit tool included has been compiled for the 68000 using
- flex 2.4.6 and byacc 1.9 under MPW 3.4. If you are compiling the
- fixit tool with different versions of these tools you may have to
- modify parts of MakeFile, fixit.y, or fixit.l.
-
-
- ROUTINES PROVIDED
-
- fixed point square root ( the root of x ):
-
- Fixed FixSqrt(Fixed x);
-
-
- fixed point exponent function ( x to the power a ):
-
- Fixed FixExp(Fixed x, Fixed a);
-
-
- fixed square (x times x):
-
- Fixed FixSquare(Fixed x);
-
-
- fixed point cosine ( the cosine of x ):
-
- Fixed FixCos(Fixed x);
-
-
- fixed point sine ( the sine of x ):
-
- Fixed FixSin(Fixed x);
-
-
- fixed point tangent ( the tangent of x ):
-
- Fixed FixTan(Fixed x);
-
-
- file fixit.txt Copyright (C) 1996 by John Montbriand. All Rights Reserved.
-
- end of file
-